import http from '/src/utils/request'
import { getCommentList } from './comment'

export function getArticles(current, size, category) {
  if (!category) return http.get(`/plugins/baliServer-module-article/api/article?current=${current}&size=${size}`)
  else
    return http.get(`/plugins/baliServer-module-article/api/article?category=${category}&current=${current}&size=${size}`)
}

export function getPostComments(current, size, postId) {
  if (isNaN(current) || isNaN(size)) return
  var x = getCommentList(1, postId, current, size)
  console.log(x)
  return x
}

export function getPostDetail(pid) {
  return http.get('/plugins/baliServer-module-article/api/article/' + pid)
}

export function pubPost(form) {
  return http.post('/plugins/baliServer-module-article/api/article', form)
}

export function getUserPost(current, size, userId) {
  return http.get(`/plugins/baliServer-module-article/api/article?current=${current}&size=${size}&userId=${userId}`)
}

export function delPost(pid) {
  return http.delete(`/plugins/baliServer-module-article/api/article/${pid}`)
}

